<?php
class Employee_model extends CI_Model
{
	public $tbl = 'employee';

	public function __contruct()
	{
		parent::__construct();	
	}

	public function All($companyId)
	{
		$queryString = "SELECT employee.*, tblDepartment.Name AS DepartmentName
						FROM employee
						join  (SELECT * FROM department WHERE CompanyId = $companyId) as tblDepartment
    					ON employee.DepartmentId = tblDepartment.Id";

		$query = $this->db->query($queryString);
		return $query->result();
	}

	public function Add($departmentId)
	{
		$data = array(
			'Firstname' => $this->input->post('Firstname'),
			'Midlename' => $this->input->post('Midlename'),
			'Lastname' => $this->input->post('Lastname'),
			'Address' => $this->input->post('Address'),
			'Phone' => $this->input->post('Phone'),
			'Phone2' => $this->input->post('Phone2'),
			'Sex' => $this->input->post('Sex'),
			'Address' => $this->input->post('Address'),
			'Email' => $this->input->post('Email'),
			'DepartmentId' => $this->input->post('DepartmentId')
			);

		return $this->db->insert($this->tbl, $data);
	}	
}
?>